package com.vhans.bapi.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.db.model.dto.friend.FriendDTO;
import com.vhans.db.model.vo.friend.FriendListVO;
import com.vhans.db.model.vo.friend.SingleRecentConversationResultVo;
import com.vhans.db.service.ICFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 好友Controller控制器
 *
 * @author vhans
 * @date 2023-05-21
 */
@Api(tags = "好友模块")
@RestController
@RequestMapping("/friend")
public class FriendController extends BaseController {
    @Autowired
    private ICFriendService friendService;

    /**
     * 查询用户的好友列表
     *
     * @return {@link FriendListVO} 好友列表
     */
    @SaCheckLogin
    @ApiOperation(value = "查询好友列表")
    @GetMapping("/myList")
    public Result<List<FriendListVO>> listFriend() {
        return Result.success(friendService.selectUserFriendVOList());
    }

    /**
     * 查询用户最近的好友列表
     *
     * @return {@link SingleRecentConversationResultVo} 最近的好友列表
     */
    @SaCheckLogin
    @ApiOperation(value = "查询用户最近的好友列表")
    @PostMapping("/recentList")
    public Result<List<SingleRecentConversationResultVo>> listRecentFriend(@RequestBody FriendDTO friendDTO) {
        return Result.success(friendService.getRecentConversation(friendDTO));
    }

    /**
     * 删除好友
     */
    @SaCheckLogin
    @ApiOperation(value = "删除好友")
    @PostMapping("/delete")
    public Result<?> deleteFriend(@RequestBody FriendDTO friend) {
        return toAjax(friendService.deleteFriend(friend));
    }
}
